<?php
header("Content-type:text/html;charset=utf8");
/**
 * Created by PhpStorm.
 * User: menghe
 * Date: 2018/5/22
 * Time: 下午2:20
 * PHP是世界上最好的语言！
 */
function dd($data){
    echo '<pre style="background: #ccc;padding: 5px;border-radius: 5px">';
    if ( is_bool ( $data ) || is_null ( $data ) ) {
        var_dump ( $data );
    } else {
        print_r ( $data );
    }
    echo '</pre>';
    die;
}
function p($data){
    echo '<pre style="background: #ccc;padding: 5px;border-radius: 5px">';
    if ( is_bool ( $data ) || is_null ( $data ) ) {
        var_dump ( $data );
    } else {
        print_r ( $data );
    }
    echo '</pre>';
}
function success($msg,$url){
    $str = <<<str
<script>
alert('{$msg}');
location.href='{$url}';
</script>
str;
    echo $str;
    exit;
}

function config($path){
//    p($path);
    $arr = explode('.',$path);
    //p($arr);
    $dirPath = '../system/config/' . $arr[0] . '.php';
    $config = include $dirPath;
    return isset($config[$arr[1]]) ? $config[$arr[1]] : NULL;
}
/**
 * 加载模板，分配变量
 * @param string $tpl
 * @param array  $args
 *
 * @return mixed
 */
function view($tpl='',$args = []){
    return \menghe\view\View::make($tpl)->with($args);
}
/**
 * 检测是否为post请求
 * 如果为post请求，IS_POST值为true
 */
define ('IS_POST',$_SERVER['REQUEST_METHOD'] == 'POST');
